package com.example.dormitorymanagement.swagger;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;


@Configuration//加了这个注解，那么就会加入到配置里面
@EnableSwagger2//开启Swagger2
public class SwaggerConfig {


    /*

   @Bean
    public Docket docket1()
    {
        return new Docket(DocumentationType.SWAGGER_2).groupName("a");
    }

     */

    //配置了swagger的docket的bean实例
    @Bean
    public Docket docket()
    {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("default")
//                .securityContexts(Arrays.asList(securityContexts()))
//                .securitySchemes(Arrays.asList(securitySchemes()))
                //.enable(false)是否启用swagger，true：开启，false：关闭
                .select()
                //requestHandlerselectors，配置要扫描接口的方式
                //basepackage,指定要扫描的包
                //any：扫描全部
                //none：不扫描
                //withClassAnnotation ： 扫描类上的注解，参数是一个注解的反射对象
                //withMethodAnnotation ：扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.example.dormitorymanagement.controller"))
                //paths() 过滤扫描路径
                //  .paths(PathSelectors.ant("com.example.demo.controller"))//不扫描这个路径
                .build();


    }






//    private SecurityScheme securitySchemes() {
//        return new ApiKey("Authorization", "Authorization", "header");
//    }
//
//    private SecurityContext securityContexts() {
//        return SecurityContext.builder()
//                .securityReferences(defaultAuth())
//                .forPaths(PathSelectors.any())
//                .build();
//    }
//    private List<SecurityReference> defaultAuth() {
//        AuthorizationScope authorizationScope = new AuthorizationScope("xxx", "描述信息");
//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
//        authorizationScopes[0] = authorizationScope;
//        return Arrays.asList(new SecurityReference("Authorization", authorizationScopes));
//        //在head请求头中添加一个键值对，name是Authorization，然后value可以在swagger-ui.html中添加
//    }


}